<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';

$return['diy']=$this->plugin_setting('diy');
if($_RQ['op']=='main'){
    $worker=pdo_get('jy_meiye_worker',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if(!$worker){
		exi('找不到员工信息！','error','jy_meiye/home/');
	}
	//今日订单数量
	$day=date("Y-m-d",time("day"));
	$today_num1=pdo_count('jy_meiye_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$worker['id'],'day'=>$day,'status'=>'1'));
	$today_num2=pdo_count('jy_meiye_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$worker['id'],'day'=>$day,'status'=>'2'));
	$today_num3=pdo_count('jy_meiye_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$worker['id'],'day'=>$day,'status'=>'4'));
	//总订单数量
	$all_num1=pdo_count('jy_meiye_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$worker['id'],'status'=>'1'));
	$all_num2=pdo_count('jy_meiye_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$worker['id'],'status'=>'2'));
	$all_num3=pdo_count('jy_meiye_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$worker['id'],'status'=>'4'));
	//总业绩
	$sql1 = "SELECT SUM(pay) FROM " . tablename('jy_meiye_order') . " WHERE uniacid=:uniacid AND worker_id=:worker_id AND status=4";
    $all_money1 = pdo_fetch($sql1,array(":uniacid" => $_SESSION['uniacid'],":worker_id" => $worker['id']));
	$sql2 = "SELECT SUM(pay) FROM " . tablename('jy_meiye_order') . " WHERE uniacid=:uniacid AND worker_id=:worker_id AND status=2";
    $all_money2 = pdo_fetch($sql2,array(":uniacid" => $_SESSION['uniacid'],":worker_id" => $worker['id']));
	//今日业绩
	$sql3 = "SELECT SUM(pay) FROM " . tablename('jy_meiye_order') . " WHERE uniacid=:uniacid AND worker_id=:worker_id AND day=:day AND status=4";
    $today_money1 = pdo_fetch($sql3,array(":uniacid" => $_SESSION['uniacid'],":worker_id" => $worker['id'],":day" => $day));
	$sql4 = "SELECT SUM(pay) FROM " . tablename('jy_meiye_order') . " WHERE uniacid=:uniacid AND worker_id=:worker_id AND day=:day AND status=2";
    $today_money2 = pdo_fetch($sql4,array(":uniacid" => $_SESSION['uniacid'],":worker_id" => $worker['id'],":day" => $day));
	//佣金
	
	$return['worker']=$worker;
	$return['today_num']=$today_num1+$today_num2+$today_num3;
	$return['all_num']=$all_num1+$all_num2+$all_num3;
	$return['all_money']=$all_money1['SUM(pay)']+$all_money2['SUM(pay)'];
	$return['today_money']=$today_money1['SUM(pay)']+$today_money2['SUM(pay)'];
	exi($return);
}
//修改员工信息
if($_RQ['op']=='set'){
	
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$data=array(
				'name'=>$postdata['name'],
				'phone'=>$postdata['mobile'],
				'headimg'=>$postdata['headimg'],
				);
		$worker_id=pdo_getcolumn('jy_meiye_worker',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');		
		if($worker_id){
			pdo_update('jy_meiye_worker',$data,array('id'=>$worker_id));
			exi('修改成功','','jy_meiye/worker_home/');		 
		}
	}
	$worker=pdo_get('jy_meiye_worker',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$return['worker']=$worker;
	exi($return);
}
